/*** 
 * @Author: Yanan Chen
 * @Date: 2021-11-02 13:47:03
 * @LastEditTime: 2021-12-13 15:21:50
 * @LastEditors: Yanan Chen
 * @Description: 
 * @FilePath: \sadwinner\fw\esp32\Src\APP\app_wifi.h
 * @
 */
#ifndef PRJ_APP_WIFI_H
#define PRJ_APP_WIFI_H

#include "hal_function.h"
#include "app_sntp.h"
enum class WIFIMODE
{
    IDLE,
    CONNECT,
    RETRY,
    DISCONNECT,
};

class AppWIFI
{
public:
    AppWIFI(){};
    ~AppWIFI(){};
    static void threadCreate();
    void init();
    void wifiConnect();
    void wifiDisConnect();
    WIFIMODE getWifiStatus()
    {
        return this->wifiStatus;
    }
    void getSSID(uint8_t *ssid)
    {
        snprintf((char *)ssid,sizeof(this->ssid),"%s",this->ssid);
    }
    void getPassword(uint8_t *passwd)
    {
        snprintf((char *)passwd,sizeof(this->password),"%s",this->password);
    }
    esp_ip4_addr_t getIP()
    {
        return s_ip_addr;
    }
private:
    WIFIMODE wifiStatus;
    WIFIMODE wifiMode;
    static TaskHandle_t  taskHandle;
    static TimerHandle_t timerHandle;
    static void thread(void *a);
    static void threadtimeCallback(TimerHandle_t handle);
    static void wifi_thread();
    static void wifi_event_handler(void* arg, esp_event_base_t event_base,int32_t event_id, void* event_data);
    static void ip_event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data);
    uint8_t ssid[32];      /**< SSID of target AP. */
    uint8_t password[64];  /**< Password of target AP. */
    esp_netif_t *wifi_netif;
    esp_ip4_addr_t s_ip_addr;
    void loadparameter();
    void wifi_start();
    void wifi_stop();
    void process();
    int doflag;
    void doIdle();
    void doConnect();
    void doRetry();
    void doDisconnect();
    
};

extern AppWIFI *wifiObj;


#endif